Spotify - Get Current Device ID
(24 actions, 29 KB)
0 Comment
https://developer.spotify.com/documentation/web-api/reference/get-a-users-available-devices
1 Text »
Spotify
2 Run Shortcut
Refresh Access Token
➔ accessToken
»
Input
:
[1 Text]
Workflow
:
{ "workflowIdentifier": "2F0DF206-94E7-4B0B-932C-9218D668A5DD", "workflowName": "Refresh Access Token", "isSelf": false }
3 Get Contents of URL
https://api.spotify.com/v1/me/player/devices
»
4
10
HTTPBodyType
:
File
ShowHeaders
:
true
HTTPHeaders
:
{ "Authorization": "Bearer
[2 accessToken]
" }
HTTPMethod
:
GET
4 Repeat with Each in
[3 Contents of URL
as Dictionary.devices
]
5 Get Dictionary Value for
name
in
[Repeat Item]
»
8
6 Dictionary
➔ mappingDict
»
7
9
{ "macOS": { "name": "
[DeviceDetails
’s Name
]
", "type": "computer" }, "iOS": { "name": "
[DeviceDetails
’s Device Model
]
", "type": "smartphone" } }
7 Get Dictionary Value for
[DeviceDetails
’s OS
]
.name
in
[6 mappingDict]
➔ name
»
8 If
[5 Dictionary Value
’s Name
]
is
[7 name]
9 Get Dictionary Value for
[DeviceDetails
’s OS
]
.type
in
[6 mappingDict]
➔ type
»
10 Match Text
[9 type]
in
[3 Contents of URL
as Dictionary.devices
]
»
MatchTextCaseSensitive
:
false
11 Count Items in
[10 Matches]
»
12 If
[11 Count]
>
1
13 Get Dictionary Value for
is_active
in
[Repeat Item]
»
14 If
[13 Dictionary Value
as Boolean’s Name
]
is true
ConditionalActionString
:
No
15 Get Dictionary Value for
id
in
[Repeat Item]
➔ deviceId
»
16 Actions > GlobalVariableSetText
value
:
[15 deviceId]
key
:
deviceId
17 End If
18 Otherwise ▵
12
19 Get Dictionary Value for
id
in
[Repeat Item]
➔ deviceId
»
20 Actions > GlobalVariableSetText
value
:
[19 deviceId]
key
:
deviceId
21 End If
22 End If ▵
8
23 End Repeat with Each ▵
4